Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce queries from unfillable updater #3107

Merged
merged 6 commits into from
Sep 7, 2023

Conversation

anxolin
Copy link
Contributor

@anxolin anxolin commented Sep 5, 2023

Summary

This PR reduces drastically the number of quotes we do.

Why?
Because the Unfillable Orders Updater was being "re-renderer" often. The re-rendering was making us to re-start the polling count (reset the timer), but also we were eagerly querying the quote!!

Ok, but why so many re-renders
It turns out, the updater had a useEffect who create the polling logic. This useEffect depended on a function to do the actual update. This function changes often. However, even if this function changes, we don't want to re-fetch again.

Soluton, proposed in this PR
Instead of depending on the function itself, we depend on a reference to it.

This way, we don't need to re-render the useEffect and the polling works as expected.

Before it would send hundreds of requests, specially in case we start to get some 404
image

Now we do way less in this case:
image

@vercel
Copy link

vercel bot commented Sep 5, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
swap-dev ✅ Ready (Inspect) Visit Preview Sep 7, 2023 11:11am

🌃 Cosmos ↗︎

@alfetopito
Copy link
Collaborator

@anxolin build still failing because of the new error type

image

@anxolin anxolin added the RELEASE Included in the release that is being closed label Sep 7, 2023
@anxolin
Copy link
Contributor Author

anxolin commented Sep 7, 2023

@anxolin build still failing because of the new error type

I still need to rebase the other branch

@anxolin anxolin force-pushed the reduce-queries-from-unfillable-updater branch from 1610fee to 2aee35c Compare September 7, 2023 10:58
const enoughBalance = hasEnoughBalanceAndAllowance({
account,
amount: currencyAmount,
balances: balancesRef.current,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now balances uses a ref to not re-render the function that often, but always use the latest version of the balances

@@ -11,7 +11,7 @@ export const ContractDeploymentBlocks: Partial<Record<ChainId, number>> = {
export const MARKET_OPERATOR_API_POLL_INTERVAL = ms`2s`
// We can have lots of limit orders and it creates a high load, so we poll them no so ofter as market orders
export const LIMIT_OPERATOR_API_POLL_INTERVAL = ms`15s`
export const PENDING_ORDERS_PRICE_CHECK_POLL_INTERVAL = ms`15s`
export const PENDING_ORDERS_PRICE_CHECK_POLL_INTERVAL = ms`30s`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to poll this often

updatePending()
const interval = setInterval(updatePending, PENDING_ORDERS_PRICE_CHECK_POLL_INTERVAL)
updatePendingRef.current()
const interval = setInterval(() => updatePendingRef.current(), PENDING_ORDERS_PRICE_CHECK_POLL_INTERVAL)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updatePending function is the culpit of the re-renders that cause too many queries

@anxolin anxolin requested a review from a team September 7, 2023 11:02
@anxolin anxolin force-pushed the reduce-queries-from-unfillable-updater branch from 2aee35c to 77d6972 Compare September 7, 2023 11:06
@anxolin anxolin changed the base branch from fix-verified-quote-issue to release/1.47.0 September 7, 2023 11:07
@alfetopito alfetopito merged commit 5b7c5a4 into release/1.47.0 Sep 7, 2023
3 checks passed
@alfetopito alfetopito deleted the reduce-queries-from-unfillable-updater branch September 7, 2023 12:21
@github-actions github-actions bot locked and limited conversation to collaborators Sep 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
RELEASE Included in the release that is being closed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants